package com.start.common.dataImport;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Data
@Schema(name = "数据交换队列")
@EqualsAndHashCode
public class DataExchangeEntity {
    private String key;
    private String name;
    private String dataPath;
    @Schema(name = "处理状态 0待开始 1进行中 -1处理失败 99处理成功")
    private Integer handlerState;
    private int fileIndex;
    private long dataIndex;
    private String entityClass;
    private String serviceClass;


    public List<String> getFilePaths() {
        List<String> result = new ArrayList<>();
        if (StringUtils.isEmpty(dataPath)) return result;
        final JSONArray jsonArray = JSONArray.parseArray(dataPath);
        for (int i = 0; i < jsonArray.size(); i++) {
            final JSONObject item = jsonArray.getJSONObject(i);
            if (!item.containsKey("value") || StringUtils.isEmpty(item.getString("value"))) continue;
            result.add(item.getString("value"));
        }
        return result;

    }

}
